// pages/shareProduct/index.js
const {
  post
} = getApp();
Page({
  data: {
    goodsInfo: {},
    imageList: [],
    swipeList: [],
    share_member: "",
    showPage: false
  },
  // 初始化加载
  onLoad: function (e) {
    post(`/spread/goods/detail`, {
      unique_id: e.unique_id
    }).then(res => {
      if (res.result == 1) {
        this.setData({
          goodsInfo: res.data.goodsVO,
          imageList: res.data.goodsIntroVOList,
          swipeList: res.data.goodsGalleryList,
          share_member: res.data.share_member,
          showPage: true
        })
      };
    })
  },
  // 分享按钮
  onShareAppMessage: function (e) {
    return {
      title: e.target.dataset.title,
      path: `/pages/commodity/index?unique_id=${e.target.dataset.unique_id}&share_member=${e.target.dataset.share_member}`,
      imageUrl: e.target.dataset.original,
      success: function (res) {
        console.log("分享成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        console.log("分享失败:" + JSON.stringify(res));
      }
    }
  },
  onShow: function () {
    // 控制分享按钮
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline'],
      success(res) {
        console.log('showShareMenu', res);
      }
    });
  }
})